package com.copa.l2032;

import java.util.*;

/**
 * @author copa
 * @createDate 2022-12-29 12:52
 * @function map位运算判断法
 */
public class Test2 {

    public List<Integer> twoOutOfThree(int[] nums1, int[] nums2, int[] nums3) {
        List<Integer> resultList = new ArrayList<>();
        Map<Integer, Integer> map = new HashMap<>();
        for (int num1 : nums1) {
            map.put(num1, map.getOrDefault(num1, 0) | 1);
        }
        for (int num2 : nums2) {
            map.put(num2, map.getOrDefault(num2, 0) | 2);
        }
        for (int num3 : nums3) {
            map.put(num3, map.getOrDefault(num3, 0) | 4);
        }
        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            int key = entry.getKey();
            int value = entry.getValue();
            if ((value & value - 1) != 0) {
                resultList.add(key);
            }
        }
        return resultList;
    }

    public static void main(String[] args) {
        int[] num1 = {3,1};
        int[] num2 = {2,3};
        int[] num3 = {1,2};
        List<Integer> list = new Test2().twoOutOfThree(num1, num2, num3);
        list.forEach(System.out::println);
    }
}
